/**
 * @Created May 17, 2012 6:41:34 PM
 * @author cry30
 */
package com.philip.journal.core.controller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.mockito.Mockito;

import com.philip.journal.core.JournalTestCommon;
import com.philip.journal.core.service.ServiceProxy;

/**
 * Base class for action classes.
 *
 * @param <T> This is the type of the instance to test.
 */
public abstract class AbstractActionTestCase<T extends BaseAction> {

    /** @return Class of the instance to test. */
    protected abstract Class<T> getTestInstanceClass();

    /** The object instance to test. */
    private T testInstance;

    /** Refactored common functionality. */
    private final JournalTestCommon common = new JournalTestCommon();

    /** Subclass logger. */
    private final Log logger = LogFactory.getLog(getClass());

    /** rtfc. */
    private transient ServiceProxy mockserviceProxy;

    /** rtfc. */
    private transient ResponseHandler mockResponseHandler;

    /**
     *
     */
    @Before
    public void setUp()
    {
        mockserviceProxy = Mockito.mock(ServiceProxy.class);
        mockResponseHandler = Mockito.mock(ResponseHandler.class);
        try {
            testInstance = getTestInstanceClass().getDeclaredConstructor(new Class[] {
                    ServiceProxy.class,
                    ResponseHandler.class }).newInstance(new Object[] {
                    mockserviceProxy,
                    mockResponseHandler });
        } catch (final Exception e) {
            logger.error(e.getMessage(), e);
        }
    }

    protected JournalTestCommon getCommon()
    {
        return common;
    }

    protected T getTestInstance()
    {
        return testInstance;
    }

    protected T getSpyInstance()
    {
        return Mockito.spy(testInstance);
    }

}
